package com.bootdo.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.bootdo.loa.controller.alipay.AliPayInterceptor;

@Component
class WebConfigurer extends WebMvcConfigurerAdapter {
	public static final String index ="/index";
	@Autowired
	BootdoConfig bootdoConfig;
	
	
     /* 默认首页的设置，当输入域名是可以自动跳转到默认指定的网页*/
   
    @Override
    public void addViewControllers(ViewControllerRegistry registry)
    {   
        registry.addViewController("/").setViewName("forward:" +index);
    }

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/files/**").addResourceLocations("file:///"+bootdoConfig.getUploadPath());
		registry.addResourceHandler("/users/**").addResourceLocations("file:///"+bootdoConfig.getUploadPath1());
	}
	
	
	
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns 用于添加拦截规则
        // excludePathPatterns 用户排除拦截
        registry.addInterceptor(new AliPayInterceptor()).addPathPatterns("/alipay/**");
        super.addInterceptors(registry);
    }


}